var editFlag = undefined;//设置一个编辑标记
function formonload(){
    var currentNodeid = $("#WF_CurrentNodeid").val();
//原生datagrid
$('#controlDiv').show();
var uid=$("#WF_DocUnid").val();
$('#dc').datagrid({
        title:"仪器耗材赠送清单" ,
        singleSelect:false,
       // collapsible:true,
        method:'get',
        autoRowHeight:true,
        fitColumns:true,
        rownumbers:true,
        //idField:'WF_OrUnid',
        url:'rule?wf_num=R_CRMVR_B066&DocUnid='+uid,
        queryParams:{
           
        },
        columns:[[
            {title:'序号',field:'icon',width:30,sortable:false,checkbox:($("#WF_ReadOnly").val()!='true')?true:false},
            {title:'主键',field:'WF_OrUnid',hidden:true,sortable:false},
            {title:'产品编号',field:'cInvCode',width:100,sortable:true},
            {title:'产品名称',field:'cInvName',width:100,sortable:true},
            {title:'规格',field:'cInvStd',width:100,sortable:true},
            {title:'数量',field:'num',width:100,sortable:true,
                editor:{
                type:'numberbox',
                precision:2,
                    options:{
                      required: false,
                        width:50
                    }
                }
            },
        ]],
            onAfterEdit: function (rowIndex, rowData, changes) {//在添加完毕endEdit，保存时触发
                //alert("123");
                editFlag = undefined;//重置
            },
            onClickRow: function (rowIndex, field, value) {//双击该行修改内容
                //alert("双击行修改数据");
                field.editing = true;
                if (editFlag != undefined) {
                    $("#dc").datagrid('endEdit', editFlag);//结束编辑，传入之前编辑的行
                }
                if (editFlag == undefined) {
                    $("#dc").datagrid('beginEdit', rowIndex);//开启编辑并传入要编辑的行
                    editFlag = rowIndex;
                    if(currentNodeid!="T10002"){
                        $('#dc').datagrid('getEditor', { index: rowIndex, field: 'num'}).target.prop('disabled',true);
                    }
                }
            }
            
    });
    
    //if ($("#WF_ReadOnly").val()!='true') {
    if(currentNodeid=="T10002"){
      $('#dc').datagrid({
                toolbar: [{//在dategrid表单的头部添加按钮
                text: "新增",
                iconCls: "icon-add",
                handler: function () {
                    SelInventory();
                }
              
            }, '-', {//'-'
                text: "删除",
                iconCls: "icon-remove",
                handler: function () {
                    //选中要删除的行
                    var rows = $("#dc").datagrid("getSelections");
                    //alert("rows========"+rows);
                    if (rows.length > 0) {//选中几行的话触发事件
                        $.messager.confirm("提示", "您确定要删除这些数据吗？一旦删除，无法撤销。", function (res) {//提示是否删除
                            if (res) {
                                for (var i = 0; i < rows.length; i++) {
                                    delnum();
                                    var index = $("#dc").datagrid('getRowIndex', rows[i]);
                                    $("#dc").datagrid('deleteRow', index);
                                }
                                //operation(effectRow);
                            }
                        });
                    }
                }
            }]
      });
    
        //初始化加载预算名称
        var Processid = $("#WF_Processid").val();
        $("#BudgetCode").combobox({
            url:"rule?wf_num=R_CRMVR_B122&Processid="+Processid+"",
            valueField:'id',
            textField:'text',
            onSelect:function(newVal){
                fz1();
            }
        });
    }
    
    
    var WF_DocStatus = $("#WF_DocStatus").val();
    if(WF_DocStatus=="Draft"){
        fznext();//暂存时加载客户信息数据
        if($("#BudgetCode").val()!=""){
            fznext1();
        }
    }
    
    //回退回来的表单客户信息不能修改
    var cCusName = $("#cCusName").val();
    if(cCusName!=""){
        $('#cCusCode').attr("disabled","disabled");
    	$('#Department').attr("disabled","disabled");
    	$('#cCusDefine6').attr("disabled","disabled");
    	$('#cCusFax').attr("disabled","disabled");
    	$('#cCusPhone').attr("disabled","disabled");
    	$('#cCusHand').attr("disabled","disabled");
    	$('#Cust_TYPE').attr("disabled","disabled");
    	$('#cCusDefine7').attr("disabled","disabled");
    	$('#cCusDefine2').attr("disabled","disabled");
    }
    var BudgetCode = $("#BudgetCode").val();
    if(BudgetCode!=""){
        $("#BudgetName").attr("disabled","disabled");
        $("#CBZX").attr("disabled","disabled");
        $("#BudgetItem").attr("disabled","disabled");
    }

}

function formonsubmit(){
	var currentNodeid = $("#WF_CurrentNodeid").val();
    if(currentNodeid=="T10002"){
        stopEditRow1();
        GetEditorValList();
        //验证客户编码是否存在
    	var cCusCode = $("#cCusCode").val();
    	if(cCusCode==""){
    	    alert("【请填写客户编码！】");
    	    return false;
    	}
    	var a;
    	var cCusName = $("#cCusName").val();
    	jQuery.ajax({
            type:"post",
            async:false,
            url:"rule?wf_num=R_CRMVR_B078&cCusName="+cCusName+"&cCusCode="+cCusCode+"",
            dataType:"text",
            data:{
                cCusCode:$("#cCusCode").text()
            },
            success:function(data){
                a=data;
            }
        });
        if(a==0){
            alert("【客户名称和编码有误，请检查后重新输入！】");
            return false;
        }
        
        var docunid = $("#WF_DocUnid").val();
         //验证数量字段不能为空
    	jQuery.ajax({
    	    type:"post",
    	    async:false,
    	    url:"rule?wf_num=R_CRMVR_B120&docunid="+docunid+"",
    	    dataType:"text",
    	    data:{},
    	    success:function(data){
    	      t=data;  
    	    }
    	});
    	if(t==1){
    	    //alert("【请填写表体中数量！】");
    	    //return false;
    	}
    	
    	//验证预算名称不能为空
    	var BudgetCode = $("#BudgetCode").combobox('getValues');
    	if(BudgetCode==""){
    	    alert("请选择预算名称！");
    	    return false;
    	}
    	
    	//验证子表信息不为空
        var t;
        jQuery.ajax({
    	    type:"post",
    	    async:false,
    	    url:"rule?wf_num=R_CRMVR_B102&docunid="+docunid+"",
    	    dataType:"text",
    	    data:{},
    	    success:function(data){
    	      t=data;  
    	    }
    	});
    	if(t==0){
    	   //alert("【请填写表体信息！】");
    	   //return false;
    	}
    }
    
	//return false to exit submit
	$('#cCusCode').removeAttr("disabled");
	$('#comCode1').removeAttr("disabled");
	$('#Department').removeAttr("disabled");
	$('#cCusDefine6').removeAttr("disabled");
	$('#cCusFax').removeAttr("disabled");
	$('#cCusPhone').removeAttr("disabled");
	$('#cCusHand').removeAttr("disabled");
	$('#Cust_TYPE').removeAttr("disabled");
	$('#cCusDefine7').removeAttr("disabled");
	$('#cCusDefine2').removeAttr("disabled");
	$("#BudgetName").removeAttr("disabled");
	$("#CBZX").removeAttr("disabled");
    $("#BudgetItem").removeAttr("disabled");
	
}
function SaveDocumentCallBack(btnAction,rs){
	//保存成功后的回调函数
	alert(rs.msg); 
	location.href="view?wf_num=V_S005_G001";
	try{opener.$('#dc').datagrid('reload');}catch(e){}
	window.close();
}


//模糊查询客户名称
function getCustomerName(val){
  var b;
  var cCusName = $("#cCusName").val();
  var DepartmentID= $("#DepartmentID").val();
  //模糊匹配客户名称
  jQuery.ajax({
      type:"post",
      async:false,
      url:"rule?wf_num=R_CRMVR_B063&cCusName="+cCusName+"&DepartmentID="+DepartmentID+"",
      dataType:"text",
      data:{
         cCusName:$("#cCusName").text() 
      },
      success:function(data){
          checkword(data);
      }
  });
}

//扩展模糊查询出来的序列值
function checkword(val){
    var wordvalue=document.getElementById("cCusName").value.toLowerCase();
    var alltxt=val;
    var inhtml="<table border='2'\" width = '300px'>";
    var isyou=0;
    var alltxtName = alltxt.split(",");
    for(i=0;i<alltxtName.length;i++){
        var alltxtNameNext = alltxtName[i].split("|");
        var name = alltxtNameNext[0];
        var value = alltxtNameNext[1];
        var comCode = alltxtNameNext[2];
        inhtml=inhtml+"<tr><td onclick=\"fz(this.innerHTML)\" onmouseover=\"this.style.backgroundColor='#666666'\" onmouseout=\"this.style.backgroundColor=''\" style=\"font-weight:bold\">"
        +name+"<p style=\"display:none\">"+value+"</p>"+"<p>"+comCode+"</p>"+"<td/></tr>";
        isyou=1;
    }
    inhtml=inhtml+"</table>";
    if (isyou==1)
    {
       document.getElementById("showmenu").innerHTML=inhtml;
       document.getElementById("showmenu").style.display="";
    }
    else
    {
       document.getElementById("showmenu").innerHTML="";
       document.getElementById("showmenu").style.display="none";
    }
    if (wordvalue=="")
    {
       document.getElementById("showmenu").innerHTML="";
       document.getElementById("showmenu").style.display="none";
    }
}

//给相关联的字段赋值
function fz(val){
    var b = val.split("<");
    var c = b[1].split(">");
    var d = b[3].split(">");
    var e = d[1].split("[");
    var f = e[1].split("]");
    var a;
    //客户名称赋值
    $("#cCusName").val(b[0]);
    document.getElementById("showmenu").style.display="none";
    $("#cCusCode").val(c[1]);
    var cCusCode = $("#cCusCode").val();
    $("#cCusCode").attr("disabled","disabled");
    $("#comCode1").val(f[0]);
    var comCode = $("#comCode1").val();
    $("#comCode1").attr("disabled","disabled");
    //省份(Department)
    jQuery.ajax({
        type:"post",
        async:false,
        url:"rule?wf_num=R_CRMVR_B049&cCusCode="+cCusCode+"&comCode="+comCode+"",
        dataType:"text",
        data:{
            Department:$("#Department").text()
        },
        success:function(data){
            a = data;
        }
    });
    $("#Department").val(a);
    $("#Department").attr("disabled","disabled");
    
    //客户分类(Cust_TYPE)、客户级别（cCusDefine5）、合作状态（HZState）、合作类型(cCusDefine6)
    jQuery.ajax({
        type:"post",
        async:false,
        url:"rule?wf_num=R_CRMVR_B222&cCusCode="+cCusCode+"&comCode="+comCode+"",
        dataType:"text",
        data:{},
        success:function(data){
            a = data;
        }
    });
    var str = a.substring(1,a.length-2);
    var model =  eval("("+str+")"); 
    $("#Cust_TYPE").val(model.Cust_TYPE);
    $("#Cust_TYPE").attr("disabled","disabled");
    $("#cCusDefine5").val(model.cCusDefine5);
    $("#cCusDefine5").attr("disabled","disabled");
    $("#HZState").val(model.HZState);
    $("#HZState").attr("disabled","disabled");
    $("#cCusDefine6").val(model.cCusDefine6);
    $("#cCusDefine6").attr("disabled","disabled");
    
    //系统收货人、收货人电话、收货地址
    jQuery.ajax({
        type:"post",
        async:false,
        url:"rule?wf_num=R_CRMVR_B225&cCusCode="+cCusCode+"&comCode="+comCode+"",
        dataType:"text",
        data:{},
        success:function(data){
            a = data;
        }
    });
    var str1 = a.substring(1,a.length-2);
    var model1 =  eval("("+str1+")");
    $("#cLinkPerson").val(model1.cContactName);
    $("#cOfficePhone").val(model1.cOfficePhone);
    $("#cDeliverAdd").val(model1.cDeliverAdd);
    
    
    var a = $("#Department").val();
    //根据被授权医院名称返回其所对应的大区
    var b ;
    jQuery.ajax({
        type:"post",
        async:false,
        url:"rule?wf_num=R_CRMVR_B105&a="+a+"&cCusCode="+cCusCode+"",
        dataType:"text",
        data:{
            OldDepart:$("#OldDepart").text()
        },
        success:function(data){
            b=data;
        }
    });
    $("#OldDepart").val(b);
}


function getItem(val){
   var BudgetCode = $("#BudgetCode").val();
   var Processid = $("#WF_Processid").val();
  //模糊匹配预算名称
  jQuery.ajax({
      type:"post",
      async:false,
      url:"rule?wf_num=R_CRMVR_B074&BudgetCode="+BudgetCode+"&Processid="+Processid+"",
      dataType:"text",
      data:{
         BudgetCode:$("#BudgetCode").text() 
      },
      success:function(data){
          checkItem(data);
      }
  }); 
}

//扩展模糊查询出来的序列值
function checkItem(val){
    var wordvalue=document.getElementById("BudgetCode").value.toLowerCase();
    var alltxt=val;
    var inhtml="<table border='2'\">";
    var isyou=0;
    var alltxtName = alltxt.split(",");
    for(i=0;i<alltxtName.length;i++){
        var alltxtNameNext = alltxtName[i].split("|");
        var name = alltxtNameNext[0];
        var value = alltxtNameNext[1];
        inhtml=inhtml+"<tr><td onclick=\"fz1(this.innerHTML)\" onmouseover=\"this.style.backgroundColor='#666666'\" onmouseout=\"this.style.backgroundColor=''\" style=\"font-weight:bold\">"
        +name+"<p style=\"display:none\">"+value+"</p>"+"<td/></tr>";
        isyou=1;
    }
    inhtml=inhtml+"</table>";
    if (isyou==1)
    {
       document.getElementById("showmenu1").innerHTML=inhtml;
       document.getElementById("showmenu1").style.display="";
    }
    else
    {
       document.getElementById("showmenu1").innerHTML="";
       document.getElementById("showmenu1").style.display="none";
    }
    if (wordvalue=="")
    {
       document.getElementById("showmenu1").innerHTML="";
       document.getElementById("showmenu1").style.display="none";
    }
}

//给预算号相关字段赋值
function fz1(val){
    //var b = val.split("<");
    //var c = b[1].split(">");
    //var a;
    //客户名称赋值
    // $("#BudgetCode").val(b[0]);
    // document.getElementById("showmenu1").style.display="none";
    // $("#BudgetName").val(c[1]);
    // $("#BudgetName").attr("disabled","disabled");
    
    //获取当前选中的预算名称
    var BudgetCode = $("#BudgetCode").combobox('getValue');
    var a;
    //预算号赋值
    jQuery.ajax({
        type:"post",
        async:false,
        url:"rule?wf_num=R_CRMVR_B123&BudgetCode="+BudgetCode+"",
        dataType:"text",
        data:{
            BudgetName:$("#BudgetName").text()
        },
        success:function(data){
            a=data;
        }
    });
    $("#BudgetName").val(a);
    $("#BudgetName").attr("disabled","disabled");
    
    //成本中心赋值
    //var BudgetName = $("#BudgetName").val();
    //var BudgetCode = $("#BudgetCode").val();
    jQuery.ajax({
        type:"post",
        async:false,
        url:"rule?wf_num=R_CRMVR_B117&BudgetName="+BudgetName+"&BudgetCode="+BudgetCode+"",
        dataType:"text",
        data:{
            CBZX:$("#CBZX").text()
        },
        success:function(data){
            a=data;
        }
    });
    $("#CBZX").val(a);
    $("#CBZX").attr("disabled","disabled");
    //预算项目赋值
    jQuery.ajax({
        type:"post",
        async:false,
        url:"rule?wf_num=R_CRMVR_B118&BudgetName="+BudgetName+"&BudgetCode="+BudgetCode+"",
        dataType:"text",
        data:{
            BudgetItem:$("#BudgetItem").text()
        },
        success:function(data){
            a=data;
        }
    });
    $("#BudgetItem").val(a);
    $("#BudgetItem").attr("disabled","disabled");
    //预算号对应预算项目
    jQuery.ajax({
        type:"post",
        async:false,
        url:"rule?wf_num=R_CRMVR_B119&BudgetName="+BudgetName+"&BudgetCode="+BudgetCode+"",
        dataType:"text",
        data:{
            MapBudget:$("#MapBudget").text()
        },
        success:function(data){
            a=data;
        }
    });
    $("#MapBudget").val(a);
    $("#MapBudget").attr("disabled","disabled");
}


function GoToNextNode1(){ 
    var WF_UserName;
    var DepartmentIDNew;
    DepartmentIDNew = $("#DepartmentID").val();
    //ajax返回选择部门的ID
    var newId;
    jQuery.ajax({
        type:"post",
        async:false,
        url:"rule?wf_num=R_CRMVR_B091&DepartmentID="+DepartmentIDNew+"",
        dataType:"text",
        data:{},
        success:function(data){
           newId= data; 
        }
    });
    var NodeList=""; //获得选中的节点
    var UserList="";//办理用户
    var NodeArray="";
    var Nodeid="";
    var obj="";
    var NodeName="";
    var MaxUserNum="";
    var MinUserNum="";
    var userList="";
    var UserArray="";
    if(newId==DepartmentID){
        //alert("没有转换部门");
        //提交到下一环节
    	$('input[name="WF_NextNodeSelect"]:checked').each(function(){
    		if(NodeList==""){NodeList=$(this).val();}
    		else{NodeList+=","+$(this).val();}
    	});
    	if($('input[name="WF_NextNodeSelect"]').length>0){ //看是否可以选择环节
    		if(NodeList==""){alert("请选择一个环节再提交!");return false;}
    		//获得审批用户列表
    		NodeArray=NodeList.split(",");
    		for(var i=0;i<NodeArray.length;i++)
    		{
    			Nodeid=NodeArray[i];
    			obj=$("#WF_"+Nodeid);
    			if(obj.length>0)
    			{
    				NodeName=obj.attr("NodeName");
    				MaxUserNum=obj.attr("MaxUserNum")-0;
    				MinUserNum=obj.attr("MinUserNum")-0;
    				//userList对应的是主部门对应的审批人
    				userList=obj.val()+"";
    				UserArray=userList.split(",");
    				if(UserArray.length>MaxUserNum && MaxUserNum!=0){alert("环节("+NodeName+")超出最大可选参与人数!");return false;}
    				if((userList=="null" || userList=="") && MinUserNum!=0)
    				{
    					alert("环节("+NodeName+")没有指定任务处理人!");
    					return false;
    				}
    				if(UserArray.length<MinUserNum){alert("环节("+NodeName+")少于最小参与人数!"); return false;}
    				for(var j=0;j<UserArray.length;j++)
    				{
    					if(UserArray[j]!=""){
    						if(UserList==""){
    						    UserList=UserArray[j]+"$"+Nodeid;
    						}else{
    						    UserList+=","+UserArray[j]+"$"+Nodeid;
    						}
    					}
    				}
    			}
    		}
    		$("#WF_NextNodeid").val(NodeList);
    		$("#WF_NextUserList").val(UserList);
    	}
    }else{
        //alert("转换了部门");
        //提交到下一环节
    	$('input[name="WF_NextNodeSelect"]:checked').each(function(){
    		if(NodeList==""){NodeList=$(this).val();}
    		else{NodeList+=","+$(this).val();}
    	});
    	if($('input[name="WF_NextNodeSelect"]').length>0){ //看是否可以选择环节
    		if(NodeList==""){alert("请选择一个环节再提交!");return false;}
    		//获得审批用户列表
    		NodeArray=NodeList.split(",");
    		for(var i=0;i<NodeArray.length;i++)
    		{
    			Nodeid=NodeArray[i];
    			obj=$("#WF_"+Nodeid);
    			if(obj.length>0)
    			{
    				NodeName=obj.attr("NodeName");
    				MaxUserNum=obj.attr("MaxUserNum")-0;
    				MinUserNum=obj.attr("MinUserNum")-0;
    				//userList是选择兼职部门后对应的审批人
                    WF_UserName = $("#WF_UserName").val();//登录账户的userid
                    //获取兼职部门领导
                    jQuery.ajax({
                        type:"post",
                        async:false,
                        url:"rule?wf_num=R_CRMVR_B090&DepartmentID="+newId+"",
                        dataType:"text",
                        data:{
                            },
                        success:function(data){
                            userList = data;
                        }
                    });
    				//alert("userList========"+userList);
    				UserArray=userList.split(",");
    				if(UserArray.length>MaxUserNum && MaxUserNum!=0){alert("环节("+NodeName+")超出最大可选参与人数!");return false;}
    				if((userList=="null" || userList=="") && MinUserNum!=0)
    				{
    					alert("环节("+NodeName+")没有指定任务处理人!");
    					return false;
    				}
    				if(UserArray.length<MinUserNum){alert("环节("+NodeName+")少于最小参与人数!"); return false;}
    				for(var j=0;j<UserArray.length;j++)
    				{
    					if(UserArray[j]!=""){
    						if(userList==""){
    						    userList=UserArray[j]+"$"+Nodeid;
    						}else{
    						    userList+=","+UserArray[j]+"$"+Nodeid;
    						}
    					}
    				}
    			}
    		}
    		$("#WF_NextNodeid").val(NodeList);
    		$("#WF_NextUserList").val(userList);
    	}
    }
	SaveDocument("EndUserTask","您确认要提交本流程吗?");
}

//给客户信息相关联的字段再次赋值
function fznext(){
    var a;
    //客户名称赋值
    var cCusName = $("#cCusName").val();
    //客户编号
    jQuery.ajax({
        type:"post",
        async:false,
        url:"rule?wf_num=R_CRMVR_B115&cCusName="+cCusName+"",
        dataType:"text",
        data:{
            Department:$("#Department").text()
        },
        success:function(data){
            a = data;
        }
    });
	
    $("#cCusCode").val(a);
    $("#cCusCode").attr("disabled","disabled");
    var cCusCode = $("#cCusCode").val();
    //省份(Department)
    jQuery.ajax({
        type:"post",
        async:false,
        url:"rule?wf_num=R_CRMVR_B049&cCusCode="+cCusCode+"",
        dataType:"text",
        data:{
            Department:$("#Department").text()
        },
        success:function(data){
            a = data;
        }
    });
    $("#Department").val(a);
    $("#Department").attr("disabled","disabled");
    //document.getElementById("Department").readOnly="readonly";
    
    //客户类别(cCusDefine6)
    jQuery.ajax({
        type:"post",
        async:false,
        url:"rule?wf_num=R_CRMVR_B050&cCusCode="+cCusCode+"",
        dataType:"text",
        data:{
            cCusDefine6:$("#cCusDefine6").text()
        },
        success:function(data){
            a = data;
        }
    });
    $("#cCusDefine6").val(a);
    $("#cCusDefine6").attr("disabled","disabled");
    
    //传真号码(cCusFax)
    jQuery.ajax({
        type:"post",
        async:false,
        url:"rule?wf_num=R_CRMVR_B051&cCusCode="+cCusCode+"",
        dataType:"text",
        data:{
            cCusFax:$("#cCusFax").text()
        },
        success:function(data){
            a = data;
           
        }
    });
    $("#cCusFax").val(a);
    $("#cCusFax").attr("disabled","disabled");
    
    //电话(cCusPhone)
    jQuery.ajax({
        type:"post",
        async:false,
        url:"rule?wf_num=R_CRMVR_B052&cCusCode="+cCusCode+"",
        dataType:"text",
        data:{
          cCusPhone:$("#cCusPhone").text() 
        },
        success:function(data){
            a = data;
        }
    });
    $("#cCusPhone").val(a);
    $("#cCusPhone").attr("disabled","disabled");
    
    //手机(cCusHand)
    jQuery.ajax({
        type:"post",
        async:false,
        url:"rule?wf_num=R_CRMVR_B053&cCusCode="+cCusCode+"",
        dataType:"text",
        data:{
            cCusHand:$("#cCusHand").text()
        },
        success:function(data){
            a = data;
        }
    });
    $("#cCusHand").val(a);
    $("#cCusHand").attr("disabled","disabled");
    
    //客户类型(Cust_TYPE)
    jQuery.ajax({
        type:"post",
        async:false,
        url:"rule?wf_num=R_CRMVR_B054&cCusCode="+cCusCode+"",
        dataType:"text",
        data:{
          Cust_TYPE:$("#Cust_TYPE").text()  
        },
        success:function(data){
            a = data;
        }
    });
    $("#Cust_TYPE").val(a);
    $("#Cust_TYPE").attr("disabled","disabled");
    
    //经销商(cCusDefine7)
    jQuery.ajax({
        type:"post",
        async:false,
        url:"rule?wf_num=R_CRMVR_B055&cCusCode="+cCusCode+"",
        dataType:"text",
        data:{
            cCusDefine7:$("#cCusDefine7").text()
        },
        success:function(data){
            a = data;
        }
    });
    $("#cCusDefine7").val(a);
    $("#cCusDefine7").attr("disabled","disabled");
    
    //开票类型(cCusDefine2)
    jQuery.ajax({
        type:"post",
        async:false,
        url:"rule?wf_num=R_CRMVR_B056&cCusCode="+cCusCode+"",
        dataType:"text",
        data:{
          cCusDefine2:$("#cCusDefine2").text() 
        },
        success:function(data){
            a = data;
        }
    });
    $("#cCusDefine2").val(a);
    $("#cCusDefine2").attr("disabled","disabled");
    
    //开票方式(Invoice_Way)
    jQuery.ajax({
        type:"post",
        async:false,
        url:"rule?wf_num=R_CRMVR_B057&cCusCode="+cCusCode+"",
        dataType:"text",
        data:{
            Invoice_Way:$("#Invoice_Way").text()
        },
        success:function(data){
            a = data;
        }
    });
    $("#Invoice_Way").val(a);
    $("#Invoice_Way").attr("disabled","disabled");
    
    var a = $("#Department").val();
    //根据被授权医院名称返回其所对应的大区
    var b ;
    jQuery.ajax({
        type:"post",
        async:false,
        url:"rule?wf_num=R_CRMVR_B105&a="+a+"",
        dataType:"text",
        data:{
            FAE:$("#FAE").text()
        },
        success:function(data){
            b=data;
        }
    });
    $("#FAE").val(b);
    $("#FAE").attr("disabled","disabled");
}

//给预算号相关字段再次赋值
function fznext1(){
    //获取当前选中的预算名称
    var BudgetCode = $("#BudgetCode").combobox('getValue');
    var a;
    //预算号赋值
    jQuery.ajax({
        type:"post",
        async:false,
        url:"rule?wf_num=R_CRMVR_B123&BudgetCode="+BudgetCode+"",
        dataType:"text",
        data:{
            BudgetName:$("#BudgetName").text()
        },
        success:function(data){
            a=data;
        }
    });
    $("#BudgetName").val(a);
    $("#BudgetName").attr("disabled","disabled");
    
    //成本中心赋值
    //var BudgetName = $("#BudgetName").val();
    //var BudgetCode = $("#BudgetCode").val();
    jQuery.ajax({
        type:"post",
        async:false,
        url:"rule?wf_num=R_CRMVR_B117&BudgetName="+BudgetName+"&BudgetCode="+BudgetCode+"",
        dataType:"text",
        data:{
            CBZX:$("#CBZX").text()
        },
        success:function(data){
            a=data;
        }
    });
    $("#CBZX").val(a);
    $("#CBZX").attr("disabled","disabled");
    //预算项目赋值
    jQuery.ajax({
        type:"post",
        async:false,
        url:"rule?wf_num=R_CRMVR_B118&BudgetName="+BudgetName+"&BudgetCode="+BudgetCode+"",
        dataType:"text",
        data:{
            BudgetItem:$("#BudgetItem").text()
        },
        success:function(data){
            a=data;
        }
    });
    $("#BudgetItem").val(a);
    $("#BudgetItem").attr("disabled","disabled");
    //预算号对应预算项目
    jQuery.ajax({
        type:"post",
        async:false,
        url:"rule?wf_num=R_CRMVR_B119&BudgetName="+BudgetName+"&BudgetCode="+BudgetCode+"",
        dataType:"text",
        data:{
            MapBudget:$("#MapBudget").text()
        },
        success:function(data){
            a=data;
        }
    });
    $("#MapBudget").val(a);
    $("#MapBudget").attr("disabled","disabled");
}


//增加解除锁定表
var flag = true;
window.onbeforeunload = function () {
    if (flag) {
    var evt = window.event || arguments[0];
    var userAgent = navigator.userAgent;
        if (userAgent.indexOf("Firefox") > 0) {
             $.ajax({
                        url:'r?wf_num=R_finance_B030&WF_DocUnid='+$("#WF_DocUnid").val(),
                        type:'post',
                        dataType:'json',
                        contentType: "application/json; charset=utf-8",
                        async:false, 
                        success:function(data) {
                        }
                    });
        }
    }
}